import com.spring.student.systemDB.dao.CouserManage;
import com.spring.student.systemDB.dao.ScoreManage;
import com.spring.student.systemDB.dao.UserManage;
import com.spring.student.systemDB.student.Score;
import com.spring.student.systemDB.student.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentSystemDB {
    public static void main(String[] args) {
        ApplicationContext context;
        context = new ClassPathXmlApplicationContext("student_systemDB.xml");
        User user = (User) context.getBean("user");
        UserManage userManage = (UserManage) context.getBean("userManage");


        Score score = (Score) context.getBean("score");
        ScoreManage scoreManage = (ScoreManage) context.getBean("scoreManage");
        CouserManage courseManage = (CouserManage) context.getBean("courseManage");
        user.setNumber("1111");
        user.setPassword("1111");
        user.setIdenity("教师");
        if (userManage.login(user)){
            System.out.println(user.getIdenity()+"用户登录成功");
            System.out.println("插入111111的学生成绩");
            score.setNumber("111111");
            score.setChinese(100);
            score.setEnglish(60);
            score.setMath(60);
            System.out.println("查询所有学生的成绩");
            scoreManage.queryAllScore();
            System.out.println("更新201111的数学成绩");
            scoreManage.queryAllScore();


        }else
            System.out.println(user.getIdenity()+"用户登录成功");
        user.setNumber("1111111");
        user.setPassword("111");
        user.setIdenity("学生");
        if (userManage.login(user)){
            System.out.println(user.getIdenity()+"用户登录成功");
            System.out.println("查询成绩");
            scoreManage.queryScoreByName(user.getNumber());

            System.out.println("查询选课");
            courseManage.queryCouser();
            courseManage.queryCouser();
            try {
                System.out.println("执行选课选择");
                courseManage.slectCouser(user.getNumber(),"java");
            }catch (RuntimeException e){
                System.out.println("信息异常"+e.getMessage());
                System.out.println("执行任务回滚");
            }finally {
                System.out.println("查询待选课记录");
                courseManage.queryCouser();
            }

        }else
            System.out.println(user.getIdenity()+"用户登录失败");
        ((AbstractApplicationContext)context).close();

    }
}
